#include "widget.h"
#include "single.h"
#include "multi.h"
#include "ui_widget.h"
#include "Client.h"


Widget::Widget(QWidget *parent) :
    QWidget(parent),
    ui(new Ui::Widget)
{
    ui->setupUi(this);
    s=new single();
    s->hide();
    m=new multi();
    m->hide();


    QObject::connect(s,SIGNAL(showgb()),this,SLOT(show_game()));
    QObject::connect(m,SIGNAL(goback()),this,SLOT(show_widgem()));
    //22222222222222222222222222222222222222222222222222222222222
    QObject::connect(m,SIGNAL(gogame()),this,SLOT(show_g()));
    //22222222222222222222222222222222222222222222222222222222222222
    QObject::connect(s,SIGNAL(ret()),this,SLOT(show_widges()));

}

Widget::~Widget()
{
    delete ui;
}

void Widget::on_btnJoin_clicked()
{
    m->show();
    this->hide();
}

void Widget::on_btnQuit_clicked()
{
    this->close();
}

void Widget::show_game()
{
    g=new game();
    g->show();
    QObject::connect(g,SIGNAL(exit()),this,SLOT(show_widgeg()));
    //b->show();
    QObject::connect(m,SIGNAL(signalClient(QString)),g,SLOT(createclient(QString)));
    QObject::connect(s,SIGNAL(signalGM()),g,SLOT(createGM()));
    s->hide();
}

void Widget::show_g()
{
    g=new game();
    g->show();
    QObject::connect(g,SIGNAL(exit()),this,SLOT(show_widgeg()));
    QObject::connect(m,SIGNAL(signalClient(QStringList)),g,SLOT(createclient(QStringList)));
    QObject::connect(s,SIGNAL(signalGM()),g,SLOT(createGM()));
    m->hide();
}

void Widget::show_widgem()
{
    m->hide();
    this->show();
}

void Widget::show_widges()
{
    s->hide();
    this->show();
}

void Widget::show_widgeg()
{
    g->close();
    //b->hide();
    this->show();
}
